﻿using System;
using System.Data.SQLite;
using System.Windows.Forms;

namespace FinanceManager
{
    public partial class ChangePsw : Form
    {
        public ChangePsw()
        {
            InitializeComponent();
        }

        SQLiteCommand comm;

        private void btchangepw_Click(object sender, EventArgs e)
        {
            DBCommon.conn.Open();
            comm = DBCommon.conn.CreateCommand();
            comm.CommandText = "select pass from admin";

            SQLiteDataReader reader = comm.ExecuteReader();
            
            if (reader.Read())
            {
                if (tboldpw.Text.Equals(reader["pass"].ToString()))
                {
                    reader.Close();
                    ToChangePsw();
                }
                else
                {
                    MessageBox.Show("旧密码错误！");
                }
            }
        }

        private void ToChangePsw() {
            comm.CommandText = "update admin set pass ='"+tbnewpw.Text.ToString()+"'";
            if (comm.ExecuteNonQuery() == 1) {
                MessageBox.Show("密码修改成功！");
                DBCommon.conn.Close();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
